#include <iostream>
#include <cstdlib>

using namespace std;

struct node
{
	int value;
	node *next;
	node(int v=-1,node *nxt=NULL):value(v),next(nxt){}
};

node *reverse(node*);//直接使用node代表结构体
node *make_link();
void display(node*);

int main()
{
	node *head = make_link();
	display(head);
	head = reverse(head);
	display(head);

	return 0;
}

node* reverse(node *head)
{
	node *pre, *cur, *post;
	if(!head || !head->next)
	{
		return head;
	}
	pre = head;
	cur = head->next;
	while(cur)
	{
		post=cur->next;
		cur->next=pre;
		pre=cur;
		cur=post;
	}
	head->next=NULL;
	return pre;

}

node* make_link()
{
	node *head = new node();
	node *cur = head;
	for(int i=0;i<9;i++)
	{
		cur->value = rand()%10;
		cur->next = new node();
		cur = cur->next;
		cur->next = NULL;
	}
	cur->value = rand()%10;
	return head;
}

void display(node *head)
{
	node *cur = head;
	int Nodenum = 0;
	while(cur)
	{
		cout<<cur->value<<" ";
		Nodenum++;
		cur=cur->next;
	}
	cout<<endl;
}













